package com.me.darkness_is_coming.actors;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.me.darkness_is_coming.main.MainGame;

public class MenuButton extends Actor
{
	private Texture button_name;
	
	public static final int HOME = 0;
	public static final int PLAY = 1;
	public static final int SCORE = 2;
	public static final int OPTIONS = 3;
    public static final int PAUSE = 4;
    public static final int RULES = 5;
	public static final int EXIT = 6;
	public int status = 0;
	
	public MenuButton(Texture button_name, final int status, float x, float y, float width, float height)
	{
		this.button_name = button_name;
		setSize(width, height);
		setPosition(x, y);
		this.status = status;
		this.addListener(new InputListener()
		{
			public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
	        {
				switch (status)
				{
					case HOME:
						MainGame.getInstance().showMenu();
						break;
					case PLAY:
						MainGame.getInstance().showGame();
						break;
					case SCORE:
						MainGame.getInstance().showScore();
						break;
					case OPTIONS:
						//MainGame.getInstance().showOptions();
						break;
                    case PAUSE:
                        MainGame.getInstance().showPause();
                        break;
                    case RULES:
                        MainGame.getInstance().showRules();
                        break;
					case EXIT:
						Gdx.app.exit();
						break;
				}
				return false;
	        }
	 
	        public void touchUp (InputEvent event, float x, float y, int pointer, int button)
	        {
	        }
		});
	}
	
	public void setStatus(final int status)
	{
		if (this.status != status)
		{
			this.status = status;
			this.clearListeners();
			this.addListener(new InputListener()
			{
				public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
		        {
					switch (status)
					{
						case HOME:
							MainGame.getInstance().showMenu();
							break;
						case PLAY:
							MainGame.getInstance().showGame();
							break;
						case SCORE:
							MainGame.getInstance().showScore();
							break;
						case OPTIONS:
							//MainGame.getInstance().showOptions();
							break;
                        case PAUSE:
                            MainGame.getInstance().showPause();
                            break;
                        case RULES:
                            MainGame.getInstance().showRules();
                            break;
						case EXIT:
							Gdx.app.exit();
							break;
					}
					return false;
		        }
		 
		        public void touchUp (InputEvent event, float x, float y, int pointer, int button)
		        {
		        }
			});
		}
	}

    @Override
    public void draw(Batch batch, float parentAlpha)
    {
        batch.setColor(getColor());
        batch.draw(button_name, getX(), getY(), getWidth(), getHeight());
    }

    public void dispose()
    {
        button_name.dispose();
    }
}
